﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace myking.tools
{
    public partial class FrmCustom : Form
    {
        controlwin controlwin_ = new controlwin();

        KeyboardHook k_hook;

        private bool setWindowMode { get; set; }

        public string windowname
        {
            get
            {
                return string.IsNullOrEmpty(txtwdName.Text) ? Properties.Settings.Default.windowname : txtwdName.Text;
            }

            set
            {
                windowname = value;
            }
        }

        public FrmCustom()
        {
            InitializeComponent();
        }

        private void FrmCustom_Load(object sender, EventArgs e)
        {

            k_hook = new KeyboardHook();
            k_hook.KeyDownEvent += new KeyEventHandler(hook_KeyDown);//钩住键按下 
            k_hook.Start();//安装键盘钩子

            setWindowMode = false;//是否隐藏

        }

        /// <summary>
        /// 热键判断
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void hook_KeyDown(object sender, KeyEventArgs e)
        {
            //隐藏则显示
            if (setWindowMode)
            {
                if (e.KeyValue == (int)Keys.F10)
                {
                    controlwin_.SetwindowShow(windowname);
                }
            }

            //显示则隐藏
            if (!setWindowMode)
            {
                if (e.KeyValue == (int)Keys.F10)
                {
                    controlwin_.SetwindowHide(windowname);
                }
            }

            setWindowMode = !setWindowMode;

        }

        private void btn_close_Click(object sender, EventArgs e)
        {
            //显示
            controlwin_.SetwindowHide(windowname);
        }

        private void btnopen_Click(object sender, EventArgs e)
        {

            //显示
            controlwin_.SetwindowShow(windowname);
        }

    }


}
